package com.nobuyme.box.downUpdata;

import android.os.Handler;

import java.io.IOException;
import java.io.InputStream;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Response;

/**
 * Created by Administrator on 2017/4/20.
 */

public abstract class CallBackFileStream implements Callback {
    Handler mHandler;

    public CallBackFileStream(){}

    public CallBackFileStream(Handler handler){
        mHandler = handler;
    }

    public void onFailure(Call arg0, IOException arg1) {
        onFailure(arg1);
    }

    @Override
    public void onResponse(final Call call, final Response response) throws IOException {
        if (mHandler != null){
            mHandler.post(new Runnable() {
                @Override
                public void run() {
                    onTResponse(response, response.body().byteStream());
                }
            });
        }else{
            onTResponse(response, response.body().byteStream());
        }
    }

    public abstract void onTResponse(Response response, InputStream mInputStream);
    public abstract void onFailure(Exception arg1);
}
